#ifndef LOG_H
#define LOG_H
#include <QObject>
#include <QQmlEngine>
#include <QMutex>

class Log : public QObject
{
    Q_OBJECT

public:
    enum LogLevel{
        ACTIVE = 0,
        INFO,
        DEBUG,
        FATAL,
        CLOSE
    };
    Q_ENUM(LogLevel)

    explicit Log(QObject *parent = nullptr) {};
    ~Log() {};
    Log(const Log&) = delete;
    Log& operator=(const Log&) = delete;

    static void declareQML() {
        qmlRegisterSingletonType<Log>("Log", 1, 0, "Log", QmlMainSingletonProvider);
    }

    static void initLog();

    static QObject *QmlMainSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine) {
        Q_UNUSED(engine)
        Q_UNUSED(scriptEngine)
        QMutex lock;
        lock.lock();
        if (!instance) {
            instance = new Log();
        }
        lock.unlock();
        return instance;
    }

    Q_INVOKABLE static void logOut(QString logStr, Log::LogLevel level = Log::DEBUG);

private:
    static Log* instance;
};
#endif // LOG_H
